package com.nineclock.approve.controller;

import com.nineclock.api.approve.ApproveDefinitionControllerApi;
import com.nineclock.approve.dto.ApproveDefinitionResultDto;
import com.nineclock.approve.dto.ApproveDefinitionSaveDto;
import com.nineclock.approve.dto.ApproveGroupDefinitionDto;
import com.nineclock.approve.service.ApproveDefinitionService;
import com.nineclock.common.entity.Result;
import com.nineclock.common.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approve")
public class ApproveDefinitionController implements ApproveDefinitionControllerApi {

    @Autowired
    private ApproveDefinitionService approveDefinitionService;

    @Override
    @GetMapping("/seq")
    public Result<String> seq() {
        return Result.success(UUIDUtils.getUUID());
    }


    @Override
    @GetMapping("/approveGroupDefinition")
    public Result<List<ApproveGroupDefinitionDto>> queryApproveDefintion() {
        List<ApproveGroupDefinitionDto> definitionDtoList = approveDefinitionService.queryApproveDefintion();
        return Result.success(definitionDtoList);
    }


    @Override
    @PostMapping("/approveDefinition")
    public Result saveApproveDefintion(@RequestBody ApproveDefinitionSaveDto definitionSaveDto) {
        approveDefinitionService.saveApproveDefintion(definitionSaveDto);
        return Result.success();
    }


    @Override
    @GetMapping("/approveDefinition/{id}")
    public Result<ApproveDefinitionResultDto> queryDefinitionById(@PathVariable("id") String id) {
        ApproveDefinitionResultDto resultDto = approveDefinitionService.queryDefinitionById(id);
        return Result.success(resultDto);
    }


}
